package com.gary.springcloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author peng_rui
 * @date 2022/7/4
 */
@RestController
@RefreshScope
public class ConsumerController {
    @Resource
    private RestTemplate restTemplate;

    @Value("${service-url.nacos-user-service}")
    private String userUrl;

    @Value("${gary.user.name}")
    private String userName;

    @RequestMapping(value = "/consumer-payment", method = RequestMethod.GET)
    public String consumer() {
        return restTemplate.getForObject(userUrl + "/payment/consul", String.class, (Object) null);
    }

    @RequestMapping(value = "/user/name", method = RequestMethod.GET)
    public String username() {
        return "userName : " + userName;
    }
}
